﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bzure.Common.Core;
using Bzure.Common.Data;

namespace Bzure.Apps.Security
{
    /// <summary>
    /// 用户组影射
    /// </summary>
    public class UserGroupMap : Entity, IPostEntity
    {
        public UserGroupMap()
        {
            this.ID = string.Empty;
            this.UserID = string.Empty;
            this.GroupID = string.Empty;
        }
        public string ID { get; set; }
        public string UserID { get; set; }
        public string GroupID { get; set; }
        public EntityPostRequest ToUpdateRequest()
        {
            EntityPostRequest OrderRequest;
            if (this.IsPersisted())
            {
                OrderRequest = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Update)
                {
                    Entity = this
                };

                OrderRequest.AppendConditionMap(this.ID, () => this.ID);
            }
            else
            {
                OrderRequest = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Create)
                {
                    Entity = this
                };

                OrderRequest.AppendFieldMap(this.ID, () => this.ID);

            }
            OrderRequest.AppendFieldMap(this.GroupID, () => this.GroupID);
            OrderRequest.AppendFieldMap(this.UserID, () => this.UserID);
            return OrderRequest;
        }
        public EntityPostRequest ToDeleteRequest()
        {
            EntityPostRequest post = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Delete)
            {
                Entity = this
            };
            post.AppendConditionMap(this.ID, () => this.ID);
            return post;
        }
    }
}
